package breeze.pixel.weather.error_view.view;

import android.os.Bundle;
import android.view.View;

import breeze.pixel.weather.BaseView;
import breeze.pixel.weather.R;
import breeze.pixel.weather.apps_util.utils.API;
import breeze.pixel.weather.apps_util.utils.AppToolUtil;
import breeze.pixel.weather.apps_util.views.mtextview.MTextView;
import brz.breeze.app_utils.BAppUtils;
import brz.breeze.web_utils.BWebUtils;

public class ErrorView extends BaseView {

    private String exception;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exception);
        MTextView textView = findViewById(R.id.activityexceptionTextView1);
        exception = getIntent().getStringExtra("error");
        if (exception!=null){
            textView.setText(exception);
        }
    }

    @Override
    public void init() {

    }

    @Override
    public void initData() {

    }

    public void upload(View view) {
        if (AppToolUtil.checkNetwork(this)) {
            String api = API._API_CRASH_RECORD;
            StringBuilder post = new StringBuilder();
            post.append("error=").append(exception);
            BAppUtils.execute(()->{
                try {
                    String webData = BWebUtils.getWebData(api, post.toString(), null);
                    toast(webData);
                } catch (Exception e) {
                    e.printStackTrace();
                    toast("上传失败");
                }
            });
        } else {
            toast("无网络连接");
        }
    }

    public void restart(View view) {
        AppToolUtil.reStartApp(this);
    }
}